﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KL.Store.Web.Models;
using KL.Store.Data;
using KL.Store.Core.Domain;

namespace KL.Store.Web.Controllers
{
    [Authorize]
    public class FriendController : KL.Store.Core.Web.BaseController
    {
        #region Index

        public ActionResult Index()
        {
            return View();
        }

        #endregion

        #region Lists

        public ActionResult Lists(int? id)
        {
            WishListsModel wishListsModel = new WishListsModel();

            if (eStoreUser.AccountId > 0 && id.HasValue)
            {
                wishListsModel.WishLists = dbWishLists.GetList((int)id);
                if (wishListsModel.WishLists == null)
                {
                    wishListsModel.WishLists = new List<WishList>();
                }
            }
            else
            {
                wishListsModel.WishLists = new List<WishList>();
            }
            eStoreUser.RedirectUrl = "/Friend/Lists";
            return View(wishListsModel);
        }

        #endregion

        #region ListDetail

        public ActionResult ListDetail(int? UserId, long? ListId)
        {
            WishListDetailModel wldModel = new WishListDetailModel();
            wldModel.ListId = -1;
            wldModel.ListName = "Liste Bulunamadı!";

            if (eStoreUser.AccountId > 0 && UserId.HasValue && ListId.HasValue)
            {
                #region Find List

                WishList wl = new WishList();
                wl = dbWishLists.Get((int)UserId, (long)ListId);

                if (wl != null)
                {
                    wldModel.ListId = wl.ListId;
                    wldModel.ListName = wl.ListName;
                    wldModel.Name = wl.FirstName + " " + wl.LastName;

                    IList<WishListDetail> wld = dbWishListDetail.GetList((int)UserId, (long)ListId);
                    if (wld != null)
                    {
                        wldModel.Products = wld;
                    }
                }

                #endregion

            }
            if (UserId.HasValue && ListId.HasValue && wldModel.ListId < 0) wldModel.FormMessage = "<script type='text/javascript'> window.location.href = '/Friend/Lists';</script>";

            return View(wldModel);
        }

        #endregion
    }
}
